<template>
  <component :is="ct.comp.guide" />
  <div v-if="val.comp_loading == false" :class="`comp_tj comp_${cfg.route.params.id}`">
    <div class="dljjc_box3_x">
      <div class="nm_mtab">
        <m-tabs
          :value="cfg.route.params?.id"
          :data="val"
          @update:value="ct.tabhand"
          :list="ct.tablist"
        />
      </div>
      <template v-if="ct.comp[cfg.route.params.id] != null">
        <template v-if="ct.get_tabck() == true">
          <template v-if="cfg.guild_id == null">
            <component :is="ct.comp.noguild" />
          </template>
          <template v-else>
            <div class="_mbbox boxgap">
              <component :tjval="val" :is="ct.comp.guild_nav" />
              <component
                v-if="val?.guild_data?.status == 'ok'"
                :is="ct.comp[cfg.route.params.id]"
                @update_load="ct.load"
                :load="val.comp_loading"
                :tjval="val"
              />
            </div>
          </template>
        </template>
        <component
          v-else
          :is="ct.comp[cfg.route.params.id]"
          @update_load="ct.load"
          :load="val.comp_loading"
          :tjval="val"
        />
      </template>
    </div>
  </div>
</template>
<style scoped>
:deep(.select_gap) {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  justify-content: center;
  gap: 8px 8px;
}
</style>
<script>
import { cfg } from "@/cfg/cfg.js";
import guide from "./set.vue";
import { getrole, getbossv2 } from "@/cfg/function.js";

export default {
  setup() {
    const ct = {
      get_tabck: () => {
        const d = ct.tablist;
        const ck = cfg.route.params.id;
        //获取d.name与ck相同的obj
        const obj = d.find((item) => item.name === ck);
        return obj?.guild ?? false;
      },
      get_season: async () => {
        try {
          const back = await cfg.mget({
            url: `${cfg.url2}api/season`,
            query: {
              type: "get_season_list",
            },
          });
          if (back.code == 0) {
            const d = back.data;
            for (let index = 0; index < d.length; index++) {
              const d2 = d[index];
              val.season_list.push({
                value: d2.sid,
                label: `${d2.name}`,
              });
              if (index == 0) {
                val.season_click = d2.sid;
              }
            }
          } else {
            throw { code: -1, message: back.msg };
          }
        } catch (e) {
          val.loading_show = false;
          cfg.alert3({
            message: e.message,
          });
        }
      },
      tabhand: (routename) => {
        cfg.router.push({
          params: {
            id: routename,
            guild_id: cfg.guild_id,
          },
        });
      },
      comp: {
        zm: defineAsyncComponent(() => import(`./comp/gh_zm.vue`)),
        rz: defineAsyncComponent(() => import(`./comp/gh_rz.vue`)),
        info: defineAsyncComponent(() => import(`./comp/gh_info.vue`)),
        report: defineAsyncComponent(() => import(`./comp/gh_report.vue`)),
        noguild: defineAsyncComponent(() => import(`./comp/gh_noguild.vue`)),
        guild_nav: defineAsyncComponent(() => import(`./comp/gh_guild_nav.vue`)),
        guide,
      },
      tablist: [
        { title: "公会招募", name: "zm" },
        { title: "公会总览", name: "info", guild: true },
        { title: "战斗记录", name: "report", guild: true },
        { title: "数据统计", name: "tj", guild: true },
        { title: "公会管理", name: "gl", guild: true },

        { title: "入驻公会", name: "rz" },
      ],
    };
    const val = reactive({
      season_list: [],
      guild_data: {},
      data: {},
      season_click: null,
      comp_loading: false,
    });
    onMounted(async () => {
      val.comp_loading = true;
      await ct.get_season();
      await getbossv2();
      if (cfg.route.params.guild_id != null && cfg.route.params.guild_id?.length > 1) {
        cfg.guild_id = cfg.route.params.guild_id ?? null;
      } else {
        cfg.guild_id = localStorage.getItem("guild_id") ?? null;
      }
      if (cfg.route.params.season != null && parseInt(cfg.route.params.season) > 0) {
        cfg.guild_season = parseInt(cfg.route.params.season);
        val.season_click = cfg.guild_season;
      } else {
        cfg.guild_season = val.season_click;
      }
      if (cfg.guild_id != null) {
        cfg.router.replace({
          params: {
            id: cfg.route.params.id,
            guild_id: cfg.guild_id,
          },
        });
        //guild_id
      }
      val.comp_loading = false;
    });
    return { cfg, ct, val };
  },
};
</script>
